package com.itany.corejava.code08_常用类.内部类;

/**
 * @author 石小俊
 * 2024年07月23日 15:21
 */
public class Test01_成员内部类 {
    public static void main(String[] args) {
        Outer outer = new Outer();
        outer.show();

        // 在其他类中定义指定类中的内部类
        // 需要先定义外部类
        // 然后通过外部类对象.new 内部类()来获取
        // 语法:外部类.内部类 变量名 = 外部类对象.new 内部类()
        Outer.Inner inner = outer.new Inner();
        inner.print();
    }
}

class Outer {
    private String name = "admin";
    private int age;

    public Outer(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public Outer() {
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    // 外部类方法
    public void show() {
        System.out.println("*********************外部类方法*********************");
        Inner inner = new Inner();
        inner.gender = "男";
        inner.name = "jack";
        System.out.println(inner.name);
        System.out.println(inner.gender);
    }

    // 定义一个成员内部类
    class Inner {
        private String name = "alice";
        private String gender;

        // 内部类方法
        public void print() {
            System.out.println("*********************内部类方法*********************");
            System.out.println(name);
            System.out.println(age);
            System.out.println(gender);
            System.out.println(this.name);
            Outer outer = new Outer();
            System.out.println(outer.name);
            System.out.println(Outer.this.name);
        }

        public Inner(String name, String gender) {
            this.name = name;
            this.gender = gender;
        }

        public Inner() {
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getGender() {
            return gender;
        }

        public void setGender(String gender) {
            this.gender = gender;
        }
    }

}